$(()=>{
    // console.log("要回显的id:"+id)
    findById(id);


    //渲染出生日期
    layui.use(function () {
        const laydate = layui.laydate;
        laydate.render({
            elem: "#dateTime",
            type: "date"
        });
    });
})

function submitEditMovie(cb=$.noop){
    // console.log("确定修改的id"+id)
    let name=$("#name").val();
    let actor=$("#actor").val();
    let dateTime=$("#dateTime").val();
    let movieTime=$("#movieTime").val();
    let rating=$("#rating").val();
    let money=$("#money").val();
    // console.log(cardId,name,sex,phone,pinyin,weixin)
    if (name.trim()===""){
        layer.msg("请输入电影名称");
        return;
    }
    if (actor.trim()===""){
        layer.msg("请输入主演");
    }
    $.ajax({
        url:ctx+"/movie/edit?id="+id,
        method:"POST",
        data:{
            name,
            actor,
            dateTime,
            movieTime,
            rating,
            money,
        },
        success:function(data){
          cb(data.success)
        }
    })

}
function findById(id){
    $.ajax({
        url:ctx+"/movie/id",
        method:"get",
        data:{
            id
        },
        dataType:"json",
        success:function(data){
            // console.log("开始赋值"+data)
            const movie = data.movie;
            console.log("要回显的对象"+movie)
            $("#name").val(movie.name);
            $("#actor").val(movie.actor);
            $("#dateTime").val(movie.dateTime);
            $("#movieTime").val(movie.movieTime);
            $("#rating").val(movie.rating);
            $("#money").val(movie.money);

        }
    })
}